<?php
/**
 * @author tungck
 * @filesource positionModel.php
 * file model for process position manager
*/
?>

<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class position_model extends CI_Model{
    
    public $tableName = 'chucdanh';
    
    function __construct(){
        parent::__construct();
        $this->load->helper('url');
        $this->load->database();
        
    }
    
    // lay danh sách vi tri chuc danh
    function getList($data){
        $recordCount = $this->db->count_all_results('chucdanh');
        $query = $this->db->query("SELECT * FROM chucdanh ORDER BY " . $data['sort'] . " LIMIT " . $data['startIndex'] . "," . $data['pageSize'] . ";");
        if($query){
            $result['query'] = $query->result();
            $result['recordCount'] = $recordCount;
            return $result;
        }else{
            return false;
        }
        
    }
    
    function getAll(){
        $query = $this->db->query("SELECT * FROM chucdanh");
        if($query){
            return $query->result();
        }else{
            return false;
        }
        
    }
    
    
    function getById($id){
        $query = $this->db->query("SELECT TenChucDanh FROM chucdanh WHERE MaChucDanh = ".$id);
        if($query){
            return $query->result();
        }else{
            return false;
        }
        
    }
    
    function insertPosition($data){
        $this->db->insert('chucdanh', $data);
        $query = $this->db->get_where('chucdanh', 'MaChucDanh = LAST_INSERT_ID()');
        if($query){
            return $query->result();
        }else{
            return false;
        }
    }
    
    function deletePosition($id){
        $this->db->delete('chucdanh', array('MaChucDanh'=>$id));
    }
    
    function updatePosition($data){
        $this->db->where('MaChucDanh', $data['MaChucDanh']);
        $this->db->update('chucdanh', $data); 
    }
    
}

?>